<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div align="center">
    <h3>获取授权认证</h3>
    <div style="margin-top: 150px;">
        <a href="#" onclick="jumpTokenFunction();"><button style='cursor:pointer;color:red;width=50px;height:50px;'>授权成功，获取认证</button></a>
    </div>

</div>
</body>
<script src="./res/js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

    /**
     * 获取授权码
     * */
    function jumpTokenFunction() {
        var code = getQueryString("code"); //
        var taxNum = getQueryString("taxnum");
        var _url = "https://opentest.jss.com.cn/accessToken"; //获取token地址
        var client_id = "yb1OQpps";  //创建应用后，分配给应用的appKey
        var client_secret = "7A4796A291CE43B1"; //创建应用后，分配给应用的appSecret
        var grant_type = "authorization_code";   //授权类型，在本步骤中，此值为“authorization_code”
        var redirect_uri = "http://172.30.5.96:8080/";   //回调地址，必传且不能为空
        $.ajax({
            type:"post",
            url:_url,
            data:{"client_id":client_id,"client_secret":client_secret,"grant_type":grant_type,"redirect_uri":redirect_uri
                    ,"code":code,"taxNum":taxNum},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success: function (data) {
                alert("认证成功");
                console.info(data);
            },
            error: function (data) {
                alert("认证失败:" + data.responseText)
                console.info(data.responseText);
            }
        });
    };

    /**
     * 获取url 后缀参数
     * @param name
     * @returns {null}
     */
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    };

</script>
</html>